home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 02 / controls / libentry.asm < prev    next >
Assembly Source File  |  1992-02-29  |  2KB  |  77 lines

  1. ;
  2. ; LIBENTRY.ASM
  3. ;
  4. ; Windows DLL entry code
  5. ;
  6. ; LibEntry resides in the _INIT code segment, initializes the DLL's
  7. ; local heap, then calls the C LibMain function that should have the
  8. ; form:
  9. ; BOOL FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg,
  10. ;                         WORD   cbHeap,    LPSTR lpszCmdLine);
  11. ;
  12. ; LibEntry returns the result of LibMain back to Windows.  If this
  13. ; value is non-zero, initialization continues.  Otherwise the DLL
  14. ; is unloaded from memory and loading fails.
  15. ;
  16.  
  17. include cmacros.inc
  18.  
  19. createSeg  _INIT, _INIT, BYTE, PUBLIC, CODE
  20. sBegin     _INIT
  21. assumes CS,_INIT
  22.  
  23. ?PLM=0                       ;C naming
  24. externA  <_acrtused>         ;Insures linking Windows DLL startup code
  25.  
  26. ?PLM=1                       ;PASCAL naming
  27. externFP <LocalInit>         ;Kernel's local heap initialization function
  28. externFP <LibMain>           ;The C initialization function
  29.  
  30.  
  31.  
  32. cProc   LibEntry, <PUBLIC,FAR>
  33.  
  34. cBegin
  35.     push    di               ;Handle of the module instance
  36.     push    ds               ;Library data segment
  37.     push    cx               ;Heap size
  38.     push    es               ;Command line segment
  39.     push    si               ;Command line offset
  40.  
  41.     ;
  42.     ; Initialize a heap if one was created for this DLL.
  43.     ;
  44.     jcxz    LECallLibMain    ;CX==0 if there is no heap
  45.  
  46.     ;
  47.     ; Call the Windows function LocalInit() to set up the heap
  48.     ; LocalInit((LPSTR)start, WORD cbHeap);
  49.     ;
  50.     xor     ax,ax
  51.     cCall   LocalInit <ds, ax, cx>
  52.     or      ax,ax            ;Success?
  53.     jz      LEError          ;Quit if LocalInit failed
  54.  
  55.     ;
  56.     ; Call the C initialization function.
  57.     ;
  58.  
  59. LECallLibMain:
  60.     call    LibMain
  61.     jmp     short LEExit     ;LibMain is responsible for stack clean up
  62.  
  63. LEError:
  64.     pop     si               ;Clean up stack on a LocalInit error
  65.     pop     es
  66.     pop     cx
  67.     pop     ds
  68.     pop     di
  69.  
  70. LEExit:
  71.  
  72. cEnd
  73.  
  74. sEnd    _INIT
  75.  
  76.     end     LibEntry
  77.